// SPWLTable.cpp: implementation of the SPWLTable class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "SPWLTable.h"
#include "DatabaseElement.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#define GET_FUNCTION(A,B,C) \
	if( !this->m_pCurRecord ) \
	{ \
		return this->m_ResPtr->A(C);\
	}\
	else\
	{\
		return this->m_pCurRecord->Get##B();\
	}

namespace PDMS
{
	namespace PDMSDBIF
	{
		BEGIN_REGISTER_MAP( SPWLTable, MultiRecordsDatabaseElement)
			REGISTER( _T("SPWL"), GET_REGISTER( DatabaseElementFactory, Design_VersionOne ) )
		END_REGISTER_MAP();
		SPWLTable::SPWLTable()
		{

		}

		SPWLTable::~SPWLTable()
		{

		}
		
		StdString SPWLTable::GetOpenSQL( const StdString& strCondition )
		{
			StdString strTmp( _T("Select * from SPWL ") );
			if ( strCondition == ALLRECORD )
			{
				return strTmp;
			}
			return strTmp + _T("WHERE ") + strCondition;
			
		}

		StdString SPWLTable::GetTableName()
		{
			return StdString( _T("SPWL") );
		}

		void SPWLTable::SetData( RecordPtr_ ptr )
		{
			ASSERT( ptr != NULL );
	
			if ( ptr->IsIDModified() )
				m_ResPtr->SetLong( _T("ID"), ptr->GetID() );

			if ( ptr->IsParentIDModified() )
				m_ResPtr->SetLong( _T("ParentID"), ptr->GetParentID() );
			
			if ( ptr->IsSpecNameModified() )
				m_ResPtr->SetString( _T("SPECNAME"), ptr->GetSpecName() );

			if ( ptr->IsMaterialDirModified() )
				m_ResPtr->SetString( _T("MATERIALDIR"), ptr->GetMaterialDir() );

			if ( ptr->IsMaterialIDModified() )
				m_ResPtr->SetLong( _T("MATERIALID"), ptr->GetMaterialID() );

			if ( ptr->IsFluidDirModified() )
				m_ResPtr->SetString( _T("FLUIDDIR"), ptr->GetFluidDir() );

			if ( ptr->IsFluidIDModified() )
				m_ResPtr->SetLong( _T("FLUIDID"), ptr->GetFluidID() );

			if ( ptr->IsRatingDirModified() )
				m_ResPtr->SetString( _T("RATINGDIR"), ptr->GetRatingDir() );

			if ( ptr->IsRatingIDModified() )
				m_ResPtr->SetLong( _T("RATINGID"), ptr->GetRatingID() );

			if ( ptr->IsLineTypeDirModified() )
				m_ResPtr->SetString( _T("LINETYPEDIR"), ptr->GetLineTypeDir() );

			if ( ptr->IsLineTypeIDModified() )
				m_ResPtr->SetLong( _T("LINETYPEID"), ptr->GetLineTypeID() );
		}

		unsigned long SPWLTable::GetID() const
		{
			GET_FUNCTION(GetLong, ID, "ID")
		}
		unsigned long SPWLTable::GetParentID() const
		{
			GET_FUNCTION(GetLong, ParentID, "ParentID")
		}
		unsigned long SPWLTable::GetFluidID() const
		{
			GET_FUNCTION(GetLong, FluidID, "FLUIDID")
		}
		unsigned long SPWLTable::GetLineTypeID() const
		{
			GET_FUNCTION(GetLong, LineTypeID, "LINETYPEID")
		}
		unsigned long SPWLTable::GetMaterialID() const
		{
			GET_FUNCTION(GetLong, MaterialID, "MATERIALID")
		}
		unsigned long SPWLTable::GetRatingID() const
		{
			GET_FUNCTION(GetLong, RatingID, "RATINGID")
		}

		const StdString SPWLTable::GetFluidDir() const
		{
			GET_FUNCTION(GetString, FluidDir, "FLUIDDIR")
		}
		const StdString SPWLTable::GetLineTypeDir() const
		{
			GET_FUNCTION(GetString, LineTypeDir, "LINETYPEDIR")
		}
		const StdString SPWLTable::GetMaterialDir() const
		{
			GET_FUNCTION(GetString, MaterialDir, "MATERIALDIR")
		}
		const StdString SPWLTable::GetRatingDir() const
		{
			GET_FUNCTION(GetString, RatingDir, "RATINGDIR")
		}
		const StdString SPWLTable::GetSpecName() const
		{
			GET_FUNCTION(GetString, SpecName, "SPECNAME")
		}
					
		void SPWLTable::SetID(const unsigned long lID)
		{
			ASSERT(this->m_pCurRecord);
			m_pCurRecord->SetID(lID);
		}
		void SPWLTable::SetParentID(const unsigned long lID)
		{
			ASSERT(this->m_pCurRecord);
			m_pCurRecord->SetParentID(lID);
		}
		void SPWLTable::SetFluidID(const unsigned long lID)
		{
			ASSERT(this->m_pCurRecord);
			m_pCurRecord->SetFluidID(lID);
		}
		void SPWLTable::SetLineTypeID(const unsigned long lID)
		{
			ASSERT(this->m_pCurRecord);
			m_pCurRecord->SetLineTypeID(lID);
		}
		void SPWLTable::SetRatingID(const unsigned long lID)
		{
			ASSERT(this->m_pCurRecord);
			m_pCurRecord->SetRatingID(lID);
		}
		void SPWLTable::SetMaterialID(const unsigned long lID)
		{
			ASSERT(this->m_pCurRecord);
			m_pCurRecord->SetMaterialID(lID);
		}

		void SPWLTable::SetSpecName(const StdString& SpecName)
		{
			ASSERT(this->m_pCurRecord);
			m_pCurRecord->SetSpecName(SpecName);
		}
		void SPWLTable::SetRatingDir(const StdString& RatingDir)
		{	
			ASSERT(this->m_pCurRecord);
			m_pCurRecord->SetRatingDir(RatingDir);
		}
		void SPWLTable::SetFluidDir(const StdString& FluidDir)
		{
			ASSERT(this->m_pCurRecord);
			m_pCurRecord->SetFluidDir(FluidDir);
		}
		void SPWLTable::SetLineTypeDir(const StdString& LineTypeDir)
		{
			ASSERT(this->m_pCurRecord);
			m_pCurRecord->SetLineTypeDir(LineTypeDir);
		}
		void SPWLTable::SetMaterialDir(const StdString& MaterialDir)
		{
			ASSERT(this->m_pCurRecord);
			m_pCurRecord->SetMaterialDir(MaterialDir);
		}

	}
}



